package com.wwwc.index.web.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.SQLException;

import com.wwwc.util.web.*;

public class FileToTable {
    private String call_path;
    private String mid;

    FileToTable (String call_path, String mid) {
	this.call_path = call_path;
	this.mid = mid;
    }

    public StringBuffer getFileType (){
	StringBuffer sbf = new StringBuffer ("");
	sbf.append("<BR><BR><h2>File format utility</h2>");
	sbf.append("<FORM method='post' action='"+call_path+"'>");
	sbf.append("<TABLE border=0>");
	sbf.append("<TR><TD align='center' colspan=2><h3>Please select input file type</h3></TD></TR>");
	sbf.append("<TR><TD align=right><input type=radio name=file_type value=text> </TD>");
	sbf.append("<TD align=left><I>Text File</I></TD></TR>");
 	sbf.append("<TR><TD align=right><input type=radio name=file_type value=html> </TD>");
	sbf.append("<TD align=left><I>Html File</I></TD></TR>");
	sbf.append("<TR><TD align=right><input type=radio name=file_type value=xml>  </TD>");
	sbf.append("<TD align=left><I>XML File</I></TD></TR>");
	sbf.append("<TR><TD align=center colspan=2><BR><input type=submit name=B value=Submit style='font-size:8pt'></TD></TR>");
	sbf.append("</TABLE>");
	sbf.append("\n<input type='hidden' name='mid' value='"+mid+"'>");
	sbf.append("</FORM>");
	return sbf;
    }
    
    public StringBuffer loadFile(String file_type, String error) {
	StringBuffer sbf = new StringBuffer();
	sbf.append("\n<BR><H3>Please cut and paste your ["+file_type+"] file into text area</H3>");
	if(error != null) {
	    sbf.append("\n<img src='/images/star.gif' border='0'>");
	    sbf.append("\n<I>"+error+"</I><BR>");
	}
	sbf.append("\n<BR>");
	sbf.append("\n<TABLE border='0'>");
	sbf.append("\n<TR><TD align='center'>");
	sbf.append("\n<FORM method='post' action='"+call_path+"'>");
	sbf.append("\n<TEXTAREA name='file' rows='20' cols='60'>");
	sbf.append("\n</TEXTAREA>");
	sbf.append("\n</TD></TR>");
	sbf.append("\n<TR><TD align='center'>");
	sbf.append("\n<input type='submit' name='submit' value='Preview' style='font-size: 8pt'>");
	sbf.append("\n<input type='reset' name='R' value='Reset' style='font-size: 8pt'>");
	sbf.append("\n<input type='hidden' name='mid' value='"+mid+"'>");
	sbf.append("\n<input type='hidden' name='file_type' value='"+file_type+"'>");
	sbf.append("\n</FORM>");
	sbf.append("\n</TD></TR>");
	sbf.append("\n</TABLE>");
	
	return sbf;
    }

    public StringBuffer formatTextFile (HttpServletRequest request, String file_type) {
	HttpSession session = request.getSession(true);
	String error = null;
	StringBuffer sbf = null;
	String in = null;

	String submit = request.getParameter("submit");
	
	if(submit == null) {
	    return loadFile(file_type, null);
	}

	Vector v = null;

	if(submit.equals("Preview")) {
	    in = request.getParameter("file");
	    if(in == null || in.length()<1) {
		return loadFile(file_type, "Please cut and paste your "+file_type+" file into the text area.");
	    }
	    
	    StringTokenizer stk = new StringTokenizer(in, "\n");
	    String temp = null;
	    int m =0;
	    
	    v = new Vector();
	    
	    while(stk.hasMoreTokens()) {
		temp = stk.nextToken();
		if(temp != null) {
		    temp = temp.trim();
		    if(temp.length()>0) {	
			v.add(temp);
		    }
		}
	    }
	    session.setAttribute("InputFile", v);
	}

	v = (Vector)session.getAttribute("InputFile");
	
	if(v == null || v.isEmpty()) {
	    return loadFile(file_type, null);
	}

	if(submit.equals("Update Row")) {
	    Enumeration enum = request.getParameterNames();
	    String name   = null;
	    String delete = null;
	    String text   = null;
	    
	    Vector vd = new Vector();
	    int index = 0;
	    
	    while(enum.hasMoreElements()) {
		name = (String)enum.nextElement();
		if(name != null && name.startsWith("delete_")) {
		    delete = request.getParameter(name);
		    if(delete != null && delete.length()>0) {
			vd.add(delete);
		    }
		}
	    
		if(name != null && name.startsWith("text_")) {
		    text = request.getParameter(name);
		    index = Integer.parseInt(name.replaceAll("text_", ""));
		    if(!text.equals((String)v.elementAt(index))) {
			if(text.length()>0) {
			    v.set(index, text);
			}
			else{
			    vd.add(""+index);
			}
		    }
		}
	    }
	    
	    Vector vn = new Vector();
	    enum = v.elements();
	    int n=0;
	    while(enum.hasMoreElements()) {
		text = (String)enum.nextElement();
		if(!vd.contains(""+n)) {
		    vn.add(text);
		}
		n++;
	    }
	    v = vn;
	    session.setAttribute("InputFile", v);
	}
	   
	if(submit.equals("Update Column")) {
	    
	}

	if(v == null || v.isEmpty()) {
	    return loadFile(file_type, null);
	}
	
	String delim = request.getParameter("delim");
	if(delim == null) {
	    delim = " ";
	}

	boolean cols_even = false;
	int columns = 0;
	
	Vector vm = new Vector();

	if(true) {
	    Vector vm1 = new Vector();
	    Vector vm2 = new Vector();
	    Enumeration enum = v.elements();
	    String temp = null;
	    boolean even = true;

	    int count   = 0;
	    columns = 0;
	    StringTokenizer stk = null;
	    int row = 0;
	    while(enum.hasMoreElements()) {
		temp = (String)enum.nextElement();		
		stk = new StringTokenizer(temp, delim);
		count = stk.countTokens();
		if(columns == 0){
		    columns = count;
		}
		else {
		    if(count != columns) {
			vm1.add(""+row);
			even = false;
		    }
		    else {
			vm2.add(""+row);
		    }
		}
		row++;
	    }

	    if(vm1.size() > vm2.size()) {
		vm = vm2;
	    }
	    else {
		vm = vm1;
	    }
	    if(columns > 1 && even) {
		cols_even = true;
	    }
	}
	
	sbf = new StringBuffer();
	sbf.append("<BR><BR><h3>Please select the range of your data to save</h3>");

	if(submit.equals("Preview") || submit.equals("Edit Row") || submit.equals("Update Row")) { 
	    sbf.append("<FORM method='post' action='"+call_path+"'>");
	    sbf.append("<TABLE border='1'>");
	    
	    sbf.append("<TR><TD align='center'><B>Delete</B></TD>");
	    sbf.append("<TD align=center>");
	    sbf.append("<input type='submit' name='submit' value='Update Row' style='font-size: 8pt'>");
	    if(cols_even) {
		sbf.append("<input type='submit' name='submit' value='Edit Column' style='font-size: 8pt'>");
	    }
	    sbf.append("</TD></TR>"); 
	    
	    Enumeration enum = v.elements();
	    String temp = null;
	    int m =0;
	    while(enum.hasMoreElements()) {
		temp = (String)enum.nextElement();	
		if(vm.contains(""+m)) {	
		    sbf.append("<TR><TD><input type='checkbox' checked name=delete_"+m+" value="+m+">");
		    sbf.append("<img src=/images/star.gif></TD>");
		}
		else {
		    sbf.append("<TR><TD><input type='checkbox' name=delete_"+m+" value="+m+"></TD>");
		}
		sbf.append("<TD>");
		sbf.append("<input type='text' name='text_"+m+"' value=\""+temp+"\" size='80' style='font-size: 8pt'>");
		sbf.append("</TD></TR>");
		m++;
	    }
	   
	    sbf.append("</TABLE>");
	    sbf.append("<input type='hidden' name='mid' value='"+mid+"'>");
	    sbf.append("<input type='hidden' name='file_type' value='"+file_type+"'>");
	    sbf.append("</FORM>");
	}

	if(cols_even && (submit.equals("Edit Column") || submit.equals("Update Column"))) {
	    StringBuffer psbf = new StringBuffer();
	    sbf.append("<FORM method='post' action='"+call_path+"'>");
	    sbf.append("<TABLE border='1'>");
	    
	    sbf.append("<TR>");
	    sbf.append("<TD align=center colspan="+columns+">");
	    sbf.append("<input type='submit' name='submit' value='Update Column' style='font-size: 8pt'>"); 
	    sbf.append("<input type='submit' name='submit' value='Edit Row' style='font-size: 8pt'>"); 
	    sbf.append("</TD>");
	    sbf.append("<TR>");

	    sbf.append("<TR>");
	    for(int j=0; j<columns;j++) {
		sbf.append("<TD><input type='checkbox' name=y_"+j+" value="+j+"></TD>");
	    }

	    sbf.append("</TR>");
	    sbf.append("<TR><TD align=center colspan="+columns+">");
	    sbf.append(MyHtml.makeLinkButton("<B>Print</B>", "'"+request.getContextPath()+"/Print' target='_blank'"));
	    sbf.append("</TD>");
	    sbf.append("<TR>");

	    Enumeration enum = v.elements();
	    String temp = null;
	    String text_col = null;
	    int m =0;
	    int col = 0;
	    StringTokenizer stk = null;
	    while(enum.hasMoreElements()) {
		temp = (String)enum.nextElement();		
		sbf.append("<TR>");
		stk = new StringTokenizer(temp, delim);
		col = 0;
		while(stk.hasMoreTokens()) {
		    text_col = stk.nextToken();
		    sbf.append("<TD>");
		    sbf.append("<input type='text' name='text_column_"+col+"' value=\""+text_col+"\" size='10' style='font-size: 8pt'>");
		    sbf.append("</TD>");
		    psbf.append(text_col);
		    if(col == columns-1) {
			psbf.append("\n");
		    }
		    else {
			psbf.append(",");
		    }
		    col++;
		}
		sbf.append("</TR>");
		m++;
	    }

	    session.setAttribute("PrintBuffer", psbf);

	    sbf.append("</TABLE>");
	    sbf.append("<input type='hidden' name='mid' value='"+mid+"'>");
	    sbf.append("<input type='hidden' name='file_type' value='"+file_type+"'>");
	    sbf.append("</FORM>");
	}

	return sbf;
    }

    public StringBuffer getHtmlFile (HttpServletRequest request){

	StringBuffer error = null;
	StringBuffer sbf = null;
	String in = request.getParameter("html_text");
      
	if(in != null) {
	    if(in.length()==0) {
		error = new StringBuffer("Please cut and paste your html file into the text area.");
	    }
	    else {
		sbf = new StringBuffer();
		sbf.append("<h3>Please select the range of your data to save</h3>");
		sbf.append("<FORM method='post' action='"+call_path+"'>");
		sbf.append("<TABLE border='1'><TR><TD align='center'><B>From:</B></TD>");
		sbf.append("<TD><B>To:</B></TD><TD align='center'><B>Data</B></TD></TR>"); 

		in = in.replaceAll("\n","");
		in = in.replaceAll("</","\n</");
		in = in.replaceAll("<","\n<");
		in = in.replaceAll(">",">\n");

		StringTokenizer stk = new StringTokenizer(in, "\n");
		String temp = null;
		boolean found_end = false;
		boolean found_start = false;
		int m =0;
		while(stk.hasMoreTokens()) {
		    temp = stk.nextToken();
		    temp = temp.replaceAll("&nbsp;","");
		    temp = temp.replaceAll("&nbsp","");
		    temp = temp.trim();
		    
		    if(temp != null && temp.length()>0) {
			if(!temp.startsWith("<")) {
			    if(temp.indexOf("<") != -1) {
				temp = temp.replaceAll("<", "&lt;");
			    }
			    if(temp.indexOf(">") != -1) {
				temp = temp.replaceAll(">", "&gt;");
			    }
			    if(temp.indexOf("\"") != -1) {
				temp = temp.replaceAll("\"", "");
			    }
			    sbf.append("<TR><TD><input type='radio' name='start' value='"+m+"'></TD>");
			    sbf.append("<TD><input type='radio' name='end' value='"+m+"'></TD>");
			    sbf.append("<TD>");
			    sbf.append("<input type='text' name='text"+m+"' value=\""+temp+"\" size='30' style='font-size: 8pt'>");
			    sbf.append("</TD></TR>");
			    m++;
			}
		    }
		}
		
		sbf.append("<TR><TD align='center' colspan='3'><B>Record Size:&nbsp;</B>");
		sbf.append("<input type='text' name='rsz' value='1' style='font-size: 8pt'>");
		sbf.append("</TD></TR>");
		
		sbf.append("<TR><TD align='center' colspan='3'>");
		sbf.append("<input type='submit' name='B' value='Select' style='font-size: 8pt'>");
		sbf.append("</TD></TR>");
		sbf.append("</TABLE>");
		sbf.append("<input type='hidden' name='mid' value='"+mid+"'>");
		//sbf.append("<input type='hidden' name='aid' value='"+aid+"'>");
		sbf.append("</FORM>");
	    }
	}
	return sbf;
    }

   
    
    public StringBuffer getSelectedData (HttpServletRequest request,  String save_call_back) {
	StringBuffer error   = null;
	StringBuffer sbf   = null;
	
	String aid   = request.getParameter("aid");
	try {
	    Vector vrs = null;
	    Vector vr  = null;

	    String action = request.getParameter("B");
	    if(action == null) {
		return null;
	    }

	    String rsz   = null;
	    int rz       = 1;

	    //=======================================================================
	    // save record into database
	    //=======================================================================
	    if(action.equals("Save")) {
		sbf = new StringBuffer();
		sbf.append("<BR>query="+request.getParameter("query"));
		sbf.append("<BR>rows="+request.getParameter("t_rows"));
		sbf.append("<BR>columns="+request.getParameter("t_columns"));
		return sbf;
	    }

	    //=======================================================================
	    // update records vector
	    //=======================================================================

	    if(action.equals("Update") || action.equals("Unique")) {
		Vector drv = getSelectedValueV(request, "rows", 0);
		Vector dcv = getSelectedValueV(request, "columns", 0);
		String total_rows = request.getParameter("t_rows");
		String total_cols = request.getParameter("t_columns");
		rz = Integer.parseInt(total_cols)-dcv.size();

		vrs = new Vector();		
		for(int m=0; m< Integer.parseInt(total_rows); m++) {
		    if(!drv.contains(""+m)) {
			vr = new Vector();
			for(int n=0; n< Integer.parseInt(total_cols); n++) {
			    if(!dcv.contains(""+n)) {
				vr.add(request.getParameter("record"+m+":"+n));
			    }
			}
			if(action.equals("Unique")) {
			    if(!vrs.contains(vr)) {
				vrs.add(vr);
			    }
			}
			else {
			    vrs.add(vr);
			}
		    }
		}
	    }

	    //=======================================================================
	    // generate records vector from file
	    //=======================================================================
	    String start = null;
	    String end   = null;

	    if(action.equals("Select")) {
		start = request.getParameter("start");
		end   = request.getParameter("end");
		rsz   = request.getParameter("rsz");

		if(start == null || end == null) {
		    return (new StringBuffer("<BR><B>Please select your data range</B><BR>"));
		}

		int t1 = Integer.parseInt(end);
		int t2 = Integer.parseInt(start);
		rz = Integer.parseInt(rsz);

		if((t1-t2+1)%rz != 0) {
		    error = new StringBuffer();
		    error.append("<I>Total ["+(t1-t2+1)+"] lines selected.</I><BR>");
		    error.append("<I>System can't generate record at size ["+rsz+"]</I>");
		}

		vrs = new Vector();
		vr  = new Vector();
		int m = t2;
		int j = 0;

		for(; m<=t1; m++) {
		    vr.add(request.getParameter("text"+m));
		    j++;
		    if(j == rz) {
			vrs.add(vr);
			j = 0;
			vr = new Vector();
		    }
		}
	    }

	    //=======================================================================
	    // display selected records
	    //=======================================================================
	    sbf = new StringBuffer();
	    sbf.append("<BR><h3>Total "+vrs.size()+" records have been generated</h3>");

	    if(error != null) {
		sbf.append("<TABLE border='0'><TR>");
		sbf.append("<TD><img src='/images/star.gif'></TD><TD>"+error+"</TD>");
		sbf.append("</TR></TABLE>");
	    }
		
	    sbf.append("<FORM method='post' action='"+call_path+"'>");
	    sbf.append("<TABLE>");
	    sbf.append("<TR><TD align='center'>");
	    sbf.append("<input type='submit' name='B' value='Update' style='font-size: 8pt'>");
	    if(rz==1) {
		sbf.append("<input type='submit' name='B' value='Unique' style='font-size: 8pt'>");
	    }
	    sbf.append("</TD></TR>");
	    sbf.append("</TABLE>");
	    sbf.append("<TABLE border='1'>");
		
	    sbf.append("<tr><td>Delete</td>");

	    for(int k=0; k<rz; k++) {
		sbf.append("<td><input type='checkbox' name='columns"+k+"' value='"+k+"'></td>");
	    }
	    sbf.append("</tr>");

	    int row = 0;
	    int col = 0;
	    Enumeration enums = vrs.elements();
	    Enumeration enum  = null;
	    while (enums.hasMoreElements()) {
		enum = ((Vector)enums.nextElement()).elements();
		sbf.append("<tr><td><input type='checkbox' name='rows"+row+"' value='"+row+"'></td>");
		col = 0;
		while (enum.hasMoreElements()) {
		    sbf.append("<td>");
		    sbf.append("<input type='text' size='"+100/rz+"' name='record"+row+":"+col+"' ");
		    sbf.append(" value=\""+enum.nextElement()+"\"  style='font-size: 8pt'></td>");
		    col++;
		}
		sbf.append("</tr>");
		row++;
	    }

	 
	    sbf.append("</TABLE>");
	    sbf.append("<input type='hidden' name='t_rows' value='"+row+"'>");
	    sbf.append("<input type='hidden' name='t_columns' value='"+rz+"'>");

	    //==========================================================
	    // database selection
	    //==========================================================
	    /*
	    Locale locale = request.getLocale();
	    ResourceBundle SystemInfo = ResourceBundle.getBundle("SystemInfo", locale); 
	    String databases   = SystemInfo.getString("3wcenter.databases");
	    sbf.append("<BR>");
	    sbf.append("<TABLE>");
	    sbf.append("<TR><TD align='center'>");
	    sbf.append("<B>Database:</B>");
	    sbf.append("</TD>");
	    sbf.append("<TD align='center'>");

	    String database = request.getParameter("database");
	    sbf.append(MyHtml.getOptions("database", databases, ",", false, database, "style='font-size: 8pt'"));
	    sbf.append("</TD>");
	    */
	    //==========================================================
	    // table selection
	    //==========================================================
	    /*
	    if(database != null && !database.startsWith("----")) {
		try {
		    Database db = DatabaseAdapter.getDatabase(database, SystemInfo);
		    Vector tnv = new Vector();
		    tnv = db.getTableNameV(database);
		    //System.out.println(tnv);
		    sbf.append("<TD align='center'>");
		    sbf.append("<B>Table:</B>");
		    sbf.append("</TD>");
		    sbf.append("<TD align='center'>");
		    String table_name = request.getParameter("table_name");
		    sbf.append(MyHtml.getOptions("table_name", tnv, false, table_name));
		    sbf.append("</TD>");
		    
		    sbf.append("<TD align='center'>");
		    sbf.append("<B>Table Info:</B>");
		    sbf.append("</TD>");
		    sbf.append("<TD align='center'>");
		    sbf.append("<input type='checkbox' name='show_table_info' value='1'>");
		    sbf.append("</TD>");
		}
		catch (Exception e) {
		    System.out.println("FileToTable:[getting database table names]:Error:"+e);
		}
	    }

	    sbf.append("</TR>");
	    sbf.append("</TABLE>");

	    sbf.append("<TABLE>");
	    sbf.append("<TR><TD align='center'>");
	    sbf.append("<TEXTAREA name='query' rows='3' cols='60'>");
	    sbf.append("INSERT INTO TABLE_NAME (");
	    for(int nn=1; nn<=rz;nn++) {
		sbf.append("F"+nn);
		if(nn != rz) {
		    sbf.append(",");
		}
	    }
	    sbf.append(") VALUES (");
	    for(int nn=1; nn<=rz; nn++) {
		sbf.append("?");
		if(nn != rz) {
		    sbf.append(",");
		}
	    }
	    sbf.append("); </TEXTAREA>");
	    sbf.append("</TD></TR>");
	    sbf.append("</TABLE>");

	    sbf.append("<TABLE>");
	    sbf.append("<TR><TD align='center'>");
	    sbf.append("<input type='submit' name='B' value='Update' style='font-size: 8pt'>");
	    if(rz==1) {
		sbf.append("<input type='submit' name='B' value='Unique' style='font-size: 8pt'>");
	    }
	    sbf.append("<input type='submit' name='B' value='Save' style='font-size: 8pt'>");
	    sbf.append("</TD></TR>");
	    sbf.append("</TABLE>");
	    sbf.append("<input type='hidden' name='mid' value='"+mid+"'>");
	    sbf.append("<input type='hidden' name='aid' value='"+aid+"'>");
	    sbf.append("</FORM>");
	    */

	    //=================================================================
	    // show table info
	    //================================================================
	    /*
	    String show_table_info = request.getParameter("show_table_info");
	    String table_name = request.getParameter("table_name");

	    if(show_table_info != null && show_table_info.equals("1") && table_name != null && !table_name.startsWith("---")) {
		try {
		    //Database db = DatabaseAdapter.getDatabase(database, SystemInfo);
		    //adminDatabaseManagerBean abean = new adminDatabaseManagerBean();
		    //sbf.append(abean.getTableInfo(db, table_name, false));
		}
		catch (Exception e) {
		    System.out.println("FileToTable:Error:getSelectedData:[show table info]"+e);
		}
	    }
	    */
	}
	catch (Exception e) {
	    System.out.println("FileToTable:Error:getSelectedData:"+e);
	}
	return sbf;	
    }
    
    public Vector getSelectedRecordsV (HttpServletRequest request, String call_back) {
	HttpSession session  = request.getSession(true);
	Vector vrs = (Vector)session.getAttribute("RecordsVector");

	try {
	    Vector dvrs = new Vector();
	    Vector dvcs = new Vector();
	    String tempn = null;
	    String tempv = null;

	    Enumeration enum = request.getParameterNames();
	    while(enum.hasMoreElements()) {
		tempn  = (String)enum.nextElement();
		if(tempn.startsWith("row")) {
		    tempv = request.getParameter(tempn);
		    if(tempv != null && tempv.length()>0) {
			dvrs.add(tempv);
		    }
		}
		if(tempn.startsWith("column")) {
		    tempv = request.getParameter(tempn);
		    if(tempv != null && tempv.length()>0) {
			dvcs.add(tempv);
		    }
		}
	    }
	 
	    //========================================================
	    // delete rows
	    //========================================================
	    enum = dvrs.elements();
	    String dindex = null;
	    while (enum.hasMoreElements()) {
		dindex = (String)enum.nextElement();
		System.out.println("deleted="+dindex);
		vrs.removeElementAt(Integer.parseInt(dindex));
	    }
	    vrs.trimToSize();
	}
	catch (Exception e) {
	    System.out.println("FileToTable:Error:getSelectedRecordsV:"+e);
	}
	return vrs;	
    }

    private Vector getSelectedValueV(HttpServletRequest request, String sname, int limit) {
	Vector v = new Vector();
	String tempn = null;
	String tempv = null;

	Enumeration enum = request.getParameterNames();
	while(enum.hasMoreElements()) {
	    tempn  = (String)enum.nextElement();
	    if(tempn.startsWith(sname)) {
		tempv = request.getParameter(tempn);
		if(tempv != null && tempv.length()>=limit) {
		    v.add(tempv);
		}
	    }
	}
	return v;
    }

    public StringBuffer displaySelectedRecors (HttpServletRequest request,  String call_back) {
	HttpSession session  = request.getSession(true);
	Vector vrs = null;
	StringBuffer sbf = null;
	try {
	    vrs = (Vector)session.getAttribute("RecordsVector");
	    
	    sbf = new StringBuffer();
	    if(vrs == null) {
		return sbf.append("No record has been found.");
	    }

	    sbf.append("<BR><h3>Total "+vrs.size()+" records</h3>");
	    sbf.append("<FORM method='post' action='"+call_path+"'>");
	    sbf.append("<TABLE border='1'>");

	    Enumeration enums = vrs.elements();
	    Enumeration enum  = null;
	    while (enums.hasMoreElements()) {
		enum = ((Vector)enums.nextElement()).elements();
		while (enum.hasMoreElements()) {
		    sbf.append("<td>"+enum.nextElement()+"</td>");
		}
		sbf.append("</tr>");
	    }

	    sbf.append("</TABLE>");

	    sbf.append("<TABLE>");
	    sbf.append("<TR><TD align='center'>");
	    sbf.append("<input type='submit' name='B' value='Update' style='font-size: 8pt'>");
	    sbf.append("</TD></TR>");
	    sbf.append("</TABLE>");
	    sbf.append("<input type='hidden' name='mid' value='"+mid+"'>");
	    sbf.append("<input type='hidden' name='aid' value='"+call_back+"'>");
	    sbf.append("</FORM>");
	}
	catch (Exception e) {
	    System.out.println("FileToTable:Error:displaySelectedRecords:"+e);
	}
	return sbf;	
    }
}








